package com.frontop.system.modules.file.controller;


import com.frontop.common.util.ResultJsonUtil;
import com.frontop.system.modules.file.model.SysFileGroup;
import com.frontop.system.modules.file.service.SysFileGroupService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author YangJia
 * @since 2021-12-13
 */
@RestController
@RequestMapping("/sys-file-group")
public class SysFileGroupController {
    @Autowired
    SysFileGroupService sysFileGroupService;


    @ApiOperation(value = "文件树列表")
    @GetMapping("/getFileGroupList")
    public ResultJsonUtil<Object> getFileGroupList(HttpServletRequest request) {
        List<SysFileGroup> SysFileGroupList = sysFileGroupService.getListMenuVO();
        return new ResultJsonUtil().success(SysFileGroupList);
    }

    @ApiOperation(value = "添加或修改文件目录")
    @PostMapping("/addOrUpdateFileGroup")
    public ResultJsonUtil<Object> addOrUpdateFileGroup(@RequestBody SysFileGroup sysFileGroup, HttpServletRequest request) {
        if(sysFileGroup.getParentId() == null){
            sysFileGroup.setParentId(0);
        }
        boolean result = sysFileGroupService.saveOrUpdate(sysFileGroup);
        return new ResultJsonUtil().judge(result);
    }

    @ApiOperation(value = "删除文件目录")
    @GetMapping("/deleteFileGroup/{id}")
    public ResultJsonUtil<Object> deleteFileGroup(@PathVariable("id") Integer id, HttpServletRequest request) {
        boolean result = sysFileGroupService.removeById(id);
        return new ResultJsonUtil().judge(result);
    }


}
